import unittest.case
from time import sleep
from framwork.common.tools import open_browsers
from selenium.webdriver.common.by import By

from framwork.pages.base_page import BasePage

"""
用例名称：工作动态页面(首页)
"""


class WorkUpdatesPage(BasePage):
    url = "/crm/index.php?m=dynamic&a=index"
    # 定位器
    btn_dashboard_locator = (By.LINK_TEXT, "仪表盘")  # 仪表盘菜单
    btn_my_schedule_locator = (By.LINK_TEXT, '日程')  # 我的日程
    btn_my_task_locator = (By.XPATH, "//a[contains(text(), '我的任务')]")  # 我的任务
    btn_my_office_locator = (By.LINK_TEXT, "办公室")  # 办公室

    # success_schedule_locator = (By.XPATH, "//h4[contains(text(),'日程')]")
    success_schedule_locator = (By.CLASS_NAME, "page-header")
    success_task_locator = (By.LINK_TEXT, "任务")


    def click_dashboard_button(self):
        """点击仪表盘"""
        self.click(self.btn_dashboard_locator)

    def click_my_schedule(self):
        """点击我的日程"""
        self.click(self.btn_my_schedule_locator)

    def click_my_task(self):
        """点击我的任务"""
        self.click(self.btn_my_task_locator)

    def click_my_office(self):
        """点击我的办公室"""
        self.click(self.btn_my_office_locator)

    def get_success_schedule_tips(self):
        """获取日程成功信息"""
        return self.find_element(self.success_schedule_locator).text

    def get_success_task_tips(self):
        """获取任务成功信息"""
        return self.find_element(self.success_task_locator).text

    def get_success_office_tips(self):
        """获取当前页面办公室url"""
        current_url = self.driver.current_url
        print(f"当前页面URL: {current_url}")
        return current_url
